<%-- Copyright (c) 2001 BroadVision, Inc. All rights reserved              --%>
<%-- The product described in this manual may be protected by one or more  --%>
<%-- U.S. and International patents. The BroadVision One-To-One software   --%>
<%-- is covered by U.S. patent 5,710,887.                                  --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and the BroadVision logo are registered       --%>
<%-- trademarks, and BroadVision One-To-One is a trademark of BroadVision, --%>
<%-- Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,    --%>
<%-- MD5, and RC2 are trademarks of RSA Data Security, Inc. All other      --%>
<%-- trademarks, service marks, and trade names belong to their respective --%>
<%-- owners. BroadVision, Inc. disclaims any proprietary interest in the   --%>
<%-- marks and names of others.                                            --%>
<%--                                                                       --%>


<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<SCRIPT language="javascript1.2">

<%@ include file="/mc/common/jsutils.jsp" %>

<% String ctxPath = request.getContextPath(); %>

// function to POST form parameters to a ".do"
function doAction(action, myform){
  if (myform.checkOnline.checked == true)
    myform.statusOnline.value = "true";
  else
    myform.statusOnline.value = "false";
    
  if (myform.checkOffline.checked == true)
    myform.statusOffline.value = "true";
  else
    myform.statusOffline.value = "false";

  myform.name.value = myform.name.value.replace(/^\s+/g, '').replace(/\s+$/g, '');
  myform.action = '<html:rewrite page="'+action+'" />';   
  myform.submit();
  return true;
}

// when user click "show results" button, will perform a new search
function doNewSearch (myform) {
  myform.showResults.value = "true";
  return doAction('/em/notif/alertSearch.do?actionSearch=true&pager.offset=0', myform);
}

function selectAllCheckBoxes(myform){
  if ( myform.checkOid == null ) 
    return true;
  
  if ( myform.checkOid.length == null ) {                                                                                 
    myform.checkOid.checked = true;
    return true;
  }
  
  for (i = 0; i < myform.checkOid.length; i++)
    myform.checkOid[i].checked = true;
  
  return true;
}

function validateFormBeforeDelete(myform) {
  var found = 0;

  if ( myform.checkOid == null ) {
    alert( "<bean:message bundle="em" key="emarketing.notif.alertSearchBody.msg.selectAlert"/>")
    return false;
  }

  if ( myform.checkOid.length == null ) {
    if ( myform.checkOid.checked == true )
      found = 1;
  }

  for (i = 0; i < myform.checkOid.length; i++) {
    if ( myform.checkOid[i].checked == true ) {
      found = 1;
      break;
    }
  }

  if ( found == 1 )
    return confirm("<bean:message bundle="em" key="emarketing.notif.alertSearchBody.msg.deleteAlerts"/>");
  else {
    alert( "<bean:message bundle="em" key="emarketing.notif.alertSearchBody.msg.selectAlert"/>")
    return false;
  }
}

function confirmDelete(){
  return confirm("<bean:message bundle="em" key="emarketing.notif.alertSearchBody.msg.deleteAlerts"/>");
}

</SCRIPT>

<c:set var="formBean" value="${emAlertSearchForm}" />
<c:set var="formBeanMap" value="${formBean.map}" />

<html:form action="/em/notif/alertSearch">

<!--start zone 5 content area-->      

<!--start page title area-->
<table width="100%" class="zoneFive" border="0" cellspacing="0" cellpadding="0">
  <tr> 
		<td valign="top" width="100%">
    
    <div class="pageTitle">
      <logic:equal name="emAlertSearchForm" 
                      property="showResults" 
                      value="false">
        <bean:message bundle="em" key="emarketing.notif.alertSearchBody.pageTitle"/>
      </logic:equal>
      <logic:equal name="emAlertSearchForm" 
                   property="showResults" 
                   value="true">                       
            <bean:message key="emarketing.notif.alertSearchBody.pageTitle" bundle="em"/>
            <logic:notEqual name="emAlertSearchForm" property="resultSize"	value="-1">:&nbsp;
                <bean:write name="emAlertSearchForm" property="resultSize"/> 
                <bean:message key="emarketing.notif.alertSearchBody.label.found" bundle="em"/>
            </logic:notEqual>
      </logic:equal>                     
    </div>
    
    <div class="pageSubtitle">
      <span class="left">
        <bean:message bundle="em"
          key="emarketing.notif.alertSearchBody.label.alertSearchCriteria" />
      </span>
      <span class="right">
     <!-- if there is no permit to create alert, disable create new button --> 
         <c:choose>
            <c:when test='${formBeanMap.createType}'>
                <input type="button" class="titleButton" 
                      value="<bean:message key="emarketing.notif.alertSearchBody.button.new.alert" bundle="em"/>" 
                      onClick="doAction('/em/notif/alertCreate.do', this.form);"/>
             </c:when>
         </c:choose>
      </span>
    </div>
      

<!--end page title area here-->

<!--end page tab area here-->


<table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0">

<!--start main content here-->

    <tr> 
      <td valign="top" nowrap width="15%" class="label"> 
        <bean:message key="emarketing.notif.alertSearchBody.label.name" bundle="em"/>: 
      </td>
      <td valign="top" nowrap class="labelField">
        <html:text property="name" maxlength="50" size="20"/><br>
      </td>    
      
      <td valign="top" nowrap width="15%" class="label"> 
        <bean:message key="emarketing.notif.alertSearchBody.label.description" bundle="em"/>: 
      </td>
      <td valign="top" nowrap class="labelField">
        <html:text name="emAlertSearchForm" property="description" maxlength="50" size="30"/>
      </td>     
    </tr>
    
    <tr>        
      <td valign="top" nowrap width="15%" class="label"> 
      <bean:message key="emarketing.notif.alertSearchBody.label.status" bundle="em"/>: 
      </td>
      <td valign="top" nowrap class="labelField">
        <html:hidden property="statusOnline" />
        <html:hidden property="statusOffline" />
        <html:checkbox name="emAlertSearchForm" property="checkOnline" />
        <bean:message	bundle="em" key="emarketing.notif.alertSearchBody.label.online" /> 
        <html:checkbox name="emAlertSearchForm" property="checkOffline" />
        <bean:message	bundle="em" key="emarketing.notif.alertSearchBody.label.offline" /> 
      </td>     
      
      <td valign="top" nowrap width="15%" class="label">
        <bean:message key="emarketing.notif.alertSearchBody.label.deliveryType" bundle="em"/>:
      </td>
      <td valign="top" nowrap class="labelField"> 
        <html:select  name ="emAlertSearchForm" 
                      property = "deliveryType" size="1">
          <html:option value = "any"> <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.any"/> </html:option>
          <html:option value = "email"> <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.email"/> </html:option>
          <html:option value = "inbox"> <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.inbox"/> </html:option>
        </html:select>
      </td>			
    </tr>

      <td valign="top" nowrap width="15%" class="label">
        <bean:message key="emarketing.notif.alertSearchBody.label.alertType" bundle="em"/>:
      </td>
      <td valign="top" nowrap class="labelField"> 
        <html:select property="alertType" size="1">
          <html:option value = "any"><bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.any"/></html:option>
          <html:optionsCollection name="emAlertSearchForm" property="alertTypes"/>
        </html:select>
      </td>

      <td valign="top" nowrap width="15%" class="label">
        <bean:message key="emarketing.notif.alertSearchBody.label.sortBy" bundle="em"/>:
      </td>
      <td valign="top" nowrap class="labelField"> 
        <html:select  name ="emAlertSearchForm" 
                      property = "sortByAttribute" size="1">
         <html:option value = "JOB_NAME"> <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.name"/> </html:option>
         <html:option value = "ALERT_TYPE"> <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.alertType"/> </html:option>
        </html:select>
      </td>			
    </tr>
    
    </table>
    
<!-- Show results button  -->
    <div class="pageButtonWrap" align="right">
       <html:hidden property="showResults" />
       <input type="button" class="pageButton" 
      value="<bean:message key="emarketing.notif.alertSearchBody.button.search" bundle="em"/>" 
      onClick="doNewSearch(this.form);"/>
    </div>
<!-- End Show results button  -->

    <br>
    <logic:equal name="emAlertSearchForm" 
                 property="showResults" 
                 value="true">                       
    <table class="dataTable" width="100%" border="0" cellspacing="0" cellpadding="0">
    
    <!--start subtitle row-->
    <div class="pageSubtitle">
      <span class="left">
        <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.alert.search.results"/>:&nbsp;
        <bean:write name="emAlertSearchForm" property="resultSize"/> 
        <bean:message key="emarketing.notif.alertSearchBody.label.alerts" bundle="em"/>
      </span>
    </div>
   <!--end subtitle row-->
    
   <logic:greaterThan name="emAlertSearchForm" property="resultSize" value="0">      
       <div class="globalButtonWrap">
          <span class="left">
          <!-- if there is no permit to delete alert, disable delete button --> 
               <c:choose>
                 <c:when test='${formBeanMap.deleteAllType}'>
                   <input type="button" name="selectAll" class="inputButton" 
                  onClick="check(this.form.checkOid, this)"
                    value="<bean:message key="emarketing.notif.alertSearchBody.button.select.all" bundle="em"/>"/>
                  <input type="button" name="delete" 
                   class="inputButton" 
                   onClick="if( validateFormBeforeDelete(this.form)) doAction('/em/notif/deleteAlertFromSearch.do', this.form);"
                   value="<bean:message key="emarketing.notif.alertSearchBody.button.delete" bundle="em"/>"/>
                 </c:when>
              </c:choose>             
        </span>
       </div>

          <!-- End subtitle buttons row -->
          
    <!-- End subtitle buttons row -->
    <tr> 
    <td colspan="2"> 
            
<!-- List search results -->
    <table width="100%" border="0" cellspacing="1" cellpadding="2">
      <tr class="listHeader"> 
        <th id="Checkboxes" width="3%">&nbsp;</th>
        <th valign="top" id="AlertName" align="left">
          <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.name"/>
        </th>
        <th valign="top" id="Description" align="left">
          <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.description"/>
        </th>
        <th valign="top" id="DeliveryType" align="left">
          <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.deliveryType"/>
        </th>
        <th valign="top" id="Status" align="left">
          <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.status"/>
        </th>
        <th valign="top" id="AlertType" align="left" width="9%" wrap>
          <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.alertType"/>
        </th>
        <th valign="top" id="Actions" align="left" width="9%" wrap>
          <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.action"/>
        </th>
      </tr>
  <!---  list result -->
  <c:forEach var="alert" items="${formBeanMap.searchResults}" varStatus="i">
            <c:choose>
            	<c:when test="${(i.count + 1) % 2 == 0}">
              		<tr class="listEven">
            	</c:when>
            	<c:otherwise>
              		<tr class="listOdd">
            	</c:otherwise>
          	</c:choose>

    <td valign="top" width="3%" headers="Checkboxes"> 
         <input type="checkbox" 
                name="checkOid" 
                 value="<c:out value="${alert.map.emktNotification.oid}"/>">
    </td>
    
    <!--  if viewType is true, show view link, otherwise, donot show -->  
    <td valign="top"  headers="AlertName">          
    <c:choose>
        <c:when test='${alert.map.viewType}'>
           <html:link  paramName="alert"
                       paramProperty= "emktNotification.oid"
                       paramId="oid"
                       page="/em/notif/alertSummaryView.do">
           <c:out value="${alert.map.emktNotification.name}"/>
         </html:link>
        </c:when>
        <c:otherwise>   
            <c:out value="${alert.map.emktNotification.name}"/>                         
        </c:otherwise>
    </c:choose>
    </td> 

    <td valign="top" headers="Description">
     <c:out value="${alert.map.emktNotification.description}"/>
    </td>
   <td valign="top" headers="DeliveryType">
      <c:choose>
        <c:when test='${alert.map.emktNotification.deliveryType=="bv_inbox_delivery"}'>
          <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.inbox"/>
        </c:when>
        <c:when test='${alert.map.emktNotification.deliveryType=="bv_email_delivery"}'>
          <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.email"/>
        </c:when>
      </c:choose>
   </td>
   
  <td valign="top" headers="Status">
         <c:choose>
            	<c:when test="${(alert.map.emktNotification.onlineStatus) ==1}">
              		<bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.online"/>
            	</c:when>
         </c:choose>
         <c:choose>
            	<c:when test="${(alert.map.emktNotification.onlineStatus) ==0}">
              		<bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.offline"/>
            	</c:when>
         </c:choose>
   </td>

    <td valign="top" headers="AlertType">
     <c:out value="${alert.map.emktNotification.alertType}"/>
    </td>
    
   <td valign="top" headers="Actions">  
          <!--  if editType is true, show edit icon, otherwise, donot show -->  
                <c:choose>
                   <c:when test='${alert.map.editType}'>              
                         <html:link paramName="alert" 
                                    paramProperty= "emktNotification.oid" 
                                    paramId="oid"
                                    page="/em/notif/alertSummaryEdit.do">
                                  <img src="<%= ctxPath %>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" 
                                  alt="<bean:message key="button.edit" bundle="em"/>" 
                                  title="<bean:message key="button.edit" bundle="em"/>">
                         </html:link>
                   </c:when>
               </c:choose>
            	   	
            <!--  if deleteType is true, show delete icon, otherwise, donot show -->	   	
               <c:choose>
                   <c:when test='${alert.map.deleteType}'>
                      <html:link paramName="alert"
                                 paramProperty= "emktNotification.oid"
                                 paramId="linkOid"
                                 page="/em/notif/deleteAlertFromSearch.do"                                    
                                 onclick="return confirmDelete();" >
                                 <img src="<%= ctxPath %>/mc/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" 
                                 alt="<bean:message key="button.delete" bundle="em"/>" 
                                 title="<bean:message key="button.delete" bundle="em"/> ">
                      </html:link>
                   </c:when>
               </c:choose>	   		   	        	
        </td> 
    </tr>
</c:forEach> 

     
          
    </logic:greaterThan>

    <logic:equal  name="emAlertSearchForm" property="resultSize"  value="0">
      <tr class="listOdd"> 
             <td colspan="4" valign="top" wrap class="label" width="40%" align="center"> 
               <bean:message bundle="em" key="emarketing.notif.alertSearchBody.label.no.alert"/>
             </td>
       </tr>
    </logic:equal>
    
    </table>

<c:if test="${not empty formBeanMap.searchResults}">
<%@ include file="/mc/common/pager.jsp" %>
</c:if>

        </td>
      </tr>
    </table>
    </logic:equal>

<!-- End list search result -->
<!--end zone 5 content area-->
</table>

<!--end main content area here-->

</html:form>

